﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace WindowsFormsApp1
{
   public  class DbHelper
    {
        public static readonly string conString = "server=LAPTOP-OE415MHH;uid=sa;pwd=123456;database=Blogs";

        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, sqlConnection);
            DataTable dt = new DataTable();
            sqlConnection.Open();
            dataAdapter.Fill(dt);
            return dt;
        }

        public static int AddOrEditSave(string sql)//添加与修改
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlCommand command = new SqlCommand(sql, sqlConnection);
            sqlConnection.Open();
            return command.ExecuteNonQuery();

        }


    }
}
